package org.sonar.db.dialect;

import java.sql.DatabaseMetaData;
import java.sql.SQLException;
import java.util.List;

import org.apache.commons.lang3.StringUtils;

public class Oceanbase extends AbstractDialect {
	public static final String ID = "oceanbase";
	private static final List<String> INIT_STATEMENTS = List.of();
//	private static final Version MIN_SUPPORTED_VERSION = Version.create(2, 4, 10);

	public Oceanbase() {
		super(ID, "com.oceanbase.jdbc.Driver", "1", "0", "SELECT 1 ");
	}

	@Override
	public boolean matchesJdbcUrl(String jdbcConnectionURL) {
		return StringUtils.startsWithIgnoreCase(jdbcConnectionURL, "jdbc:oceanbase:");
	}

	@Override
	public boolean supportsMigration() {
		return true;
	}

	@Override
	public List<String> getConnectionInitStatements() {
		return INIT_STATEMENTS;
	}

	@Override
	public String getSqlFromDual() {
		return "from dual";
	}

	@Override
	public void init(DatabaseMetaData metaData) throws SQLException {
//		checkDbVersion(metaData, MIN_SUPPORTED_VERSION);
		checkDriverVersion(metaData);
	}

    private static void checkDriverVersion(DatabaseMetaData metaData) throws SQLException {
//        String driverVersion = metaData.getDriverVersion();
//        String[] parts = StringUtils.split(driverVersion, ".");
//        int intVersion = Integer.parseInt(parts[0]) * 100 + Integer.parseInt(parts[1]);
//        if (intVersion < 1200) {
//            throw MessageException.of(String.format(
//              "Unsupported Oceanbase driver version: %s. Minimal supported version is 12.1.", driverVersion));
//        }
    }
}
